package com.etc.common;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Component
public class MyInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        // 某个方法
        System.out.println("我的拦截器 preHandle 方法前");
//        if (request.getRequestURI().contains("aaa")) {
//            return false;
//        }

//        HttpSession session = request.getSession();
//
//        if (session.getAttribute("user") == null) {
//            response.sendRedirect("/test.html");
//            return false;
//        }

        boolean ret = HandlerInterceptor.super.preHandle(request, response, handler);
        System.out.println("我的拦截器 preHandle 方法后");

        return ret;
    }
}
